# -*- coding: utf-8 -*-
from flask import Flask, jsonify, request, render_template, url_for, redirect
from flask import send_from_directory
import os
from subprocess import call


app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = '/Users/xiongzenghui/Desktop/updown'

@app.route('/')
def hello():
    return "Hello World, Flask!"

@app.route('/download/<filename>', methods=['GET'])
def download_file(filename):
    return send_from_directory(app.config['UPLOAD_FOLDER'], filename)


@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        file_ = request.files['file']
        filename = file_.filename
        save_file(file_, filename,)
        return 'success'
    return "must POST"

def save_file(file_, filename):
    if not os.path.exists(app.config['UPLOAD_FOLDER']):
        os.mkdir(app.config['UPLOAD_FOLDER'])
    file_.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))


def run():
    app.run()


if __name__ == '__main__':
    app.run()
